package com.polaris.live.adapter

import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.StringUtils
import com.blankj.utilcode.util.TimeUtils
import com.polaris.live.R.color.color_ffba00
import com.polaris.live.common.R.color
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.cacha.CacheUtil
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.constant.AppConst
import com.polaris.live.common.ext.convertArabicDigitsToNormal
import com.polaris.live.common.util.DateUtils
import com.polaris.live.databinding.AdapterInviteRewardBinding
import com.polaris.live.resp.back_resp.ListResultUserInviteRewardResp
import com.polaris.live.translation.R
import com.polaris.live.utils.CommonUtils
import com.polaris.live.utils.CommonUtils.toBoolean
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * InviteRewardAdapter
 *
 * @author Created by 半仙 on 2024/4/10/010 15:49
 */
class InviteRewardAdapter :
    BaseBindingAdapter<AdapterInviteRewardBinding, ListResultUserInviteRewardResp>() {
    override fun convert(
        holder: VBViewHolder<AdapterInviteRewardBinding>,
        item: ListResultUserInviteRewardResp,
    ) {
        holder.vb.apply {
            val user = item.userBasic
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(user.avatarFrame))
            avatarImg.setImageUrl(user.avatar, user.userId)
            tvInviteRewardName.text = user.nickname
            val time = item.settleTime - CacheUtil.getServerTime()
            if (time <= 0) {
                item.settle = AppConst.YESLONG
            }
            if (item.settle.toBoolean()) {
                val millis2String =
                    TimeUtils.millis2String(item.createTime, "yyyy-MM-dd HH:mm")
                        .convertArabicDigitsToNormal()
                tvInviteRewardTime.text = millis2String
                tvInviteRewardTime.setTextColor(ColorUtils.getColor(color.color_a7a8ad))
            } else {

                val formatDuration = DateUtils.formatDuration(time).convertArabicDigitsToNormal()
                tvInviteRewardTime.text =
                    StringUtils.getString(R.string.reward_count_down, formatDuration)
                tvInviteRewardTime.setTextColor(ColorUtils.getColor(color_ffba00))
            }
            tvTextCoin.text = "${item.rewardGainCoin + item.rewardSendGainCoin}"
            if (CommonUtils.isMan(UserManager.getUser().sex)) {
                ivRewardsIcon.setImageResource(com.polaris.live.R.drawable.ic_diamond_small)
            } else {
                ivRewardsIcon.setImageResource(com.polaris.live.R.drawable.ic_beans)
            }
        }
    }

}